package com.bestcem.xm.ticket.mq.receiver.biz.rabbit;


import com.bestcem.xm.ticket.mq.receiver.biz.ReceiverService;
import com.bestcem.xm.ticket.mq.receiver.biz.TicketConsumers;
import com.bestcem.xm.ticket.service.dto.OrgCreatedMessage;
import com.bestcem.xm.ticket.service.dto.mq.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "rabbit")
public class RabbitConsumers implements TicketConsumers {

    private ReceiverService receiverService;

    @Autowired
    public void setReceiverService(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }


    /**
     * 监听 工单预警触发队列MQ
     */
    @Bean
    @Override
    public Consumer<GenericMessage<TicketStatusUpdateDto>> ticketRuleTriggered() {
        return receiverService::ticketRuleTriggered;
    }

    /**
     * 工单二次投放队列消息
     */
    @Override
    @Bean
    public Consumer<GenericMessage<DeliverAgainDTO>> ticketDeliverAgain() {
        return receiverService::ticketDeliverAgain;
    }

    /**
     * 问卷创建队列消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<NotificationCreateDto>> projectCreated() {
        return receiverService::projectCreated;
    }

    /**
     * 奖励通知-工单通知触发队列消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<NotificationTriggerDTO>> notificationTrigger() {
        return receiverService::notificationTrigger;
    }

    /**
     * 用户邮箱删除队列消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<List<String>>> smtpDeleted() {
        return receiverService::smtpDeleted;
    }

    /**
     * 租户组织创建队列消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<OrgCreatedMessage>> userOrgCreated() {
        return receiverService::userOrgCreated;
    }

    /**
     * 移除微信用户订阅的所有问卷
     */
    @Bean
    @Override
    public Consumer<GenericMessage<String>> wechatUnsubscribe() {
        return receiverService::wechatUnsubscribe;
    }

    /**
     * 计算周期行任务通知 提醒消息 延时MQ
     */
    @Bean
    @Override
    public Consumer<GenericMessage<TicketSendDTO>> ticketSendNotify() {
        return receiverService::ticketSendNotify;
    }

    /**
     * 工单流转 发送提醒消息 延时MQ
     */
    @Bean
    @Override
    public Consumer<GenericMessage<FollowOverdueDTO>> ticketOverDue() {
        return receiverService::ticketOverDue;
    }

    /**
     * 答卷提交
     */
    @Bean
    @Override
    public Consumer<GenericMessage<TicketConfigCheckDTO>> surveyRespondentSubmit() {
        return receiverService::surveyRespondentSubmit;
    }
}
